﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Deeper.Common;
using Deeper.Common.Web;
using Deeper.DataAccess;
using ZhongTian.Model;
using ZhongTian.Services;



namespace ZhongTian.Web
{
	public partial class ItemClassInfo : Page
	{
		private string OrderBy { get { return ItemClass.F.ItemClassId.Name; } }

		protected PageResult MyDataBind(int pageIndex, int pageSize)
		{
			return new DataContext().GetPageList<ItemClass>(rptList.PageIndex, rptList.PageSize, orderby: OrderBy);
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
				rptList.ReBind();
		}

		protected void ModelAdd()
		{
			pnlDetail.GetEdit(new ItemClass());
		}

		protected void ModelSave()
		{
			"保存".InfoAction(() =>
			{
				int id = hfItemClassId.Value.ToInt();
				ItemClass model = id == 0 ? new ItemClass() : new DataContext().GetEntityById<ItemClass>(id);
				model.GetData(pnlDetail);
				model.Save();
				pnlDetail.Hide();
				rptList.ReBind();
			});
		}


		protected void rptList_Command(object sender, RepeaterCommandEventArgs e)
		{
			int id = e.CommandArgument.ToString().ToInt();
			string cmd = e.CommandName.ToLower();
			switch (cmd)
			{
				case "delete":
					"删除".InfoAction(() =>
					{
						new DataContext().Delete<ItemClass>(id);
						rptList.ReBind();
					});
					break;
				case "edit":
					"获取编辑信息".InfoAction(() =>
					  {
						  pnlDetail.GetEdit(new DataContext().GetEntityById<ItemClass>(id));
					  }, false);
					break;
			}
		}
	}


}